package com.ocean.web.controller.product;

import com.ocean.common.core.controller.BaseController;
import com.ocean.common.core.domain.AjaxResult;
import com.ocean.common.core.domain.entity.SysUser;
import com.ocean.common.core.page.TableDataInfo;
import com.ocean.common.utils.ShiroUtils;
import com.ocean.productCheck.domain.OProductCheckMessage;
import com.ocean.productCheck.service.IOProductCheckMessageService;
import com.ocean.system.service.ISysRoleService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 归档文件短消息提醒
 * @author msy
 * @date 2023/2/27
 */
@Controller
@RequestMapping("product/checkMessage")
public class OProductCheckMessageController extends BaseController {
    private String prefix = "product/check_message";

    @Autowired
    private IOProductCheckMessageService checkMessageService;
    @Autowired
    private ISysRoleService sysRoleService;

    @RequiresPermissions("product:checkMessage:view")
    @GetMapping
    public String view(){
        return prefix + "/checkMessage";
    }

    @PostMapping("list")
    @ResponseBody
    public TableDataInfo list(OProductCheckMessage checkMessage){
        //过滤平台管理员
        SysUser sysUser = ShiroUtils.getSysUser();
        if (sysRoleService.isDeptAdmin(sysUser)){
            checkMessage.setDepartId(sysUser.getDeptId().toString());
        }
        startPage();
        List<OProductCheckMessage> list = checkMessageService.getFormList(checkMessage);
        return getDataTable(list);
    }

    @RequiresPermissions("product:checkMessage:view")
    @PostMapping("remove")
    @ResponseBody
    public AjaxResult remove(String ids){
        return toAjax(checkMessageService.deleteByIds(ids));
    }
}
